<template>
  <div>
    <van-sticky>
        <!-- 导航栏 -->
        <van-nav-bar class="app-nav-bar" :title="clsname" left-arrow @click-left="$router.back()" />
    </van-sticky>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了"  @load="onLoad">
        <van-cell v-for="item in list" :key="item.id">
          <template>
            <div slot="title" v-html="item.resource_title"></div>
            <div slot="label">
              <span >来源数据库:{{item.resource_name}}</span>
              <span class="date">浏览时间:{{item.create_time}}</span>
            </div>
          </template>
        </van-cell>
    </van-list>
</div>

</template>

<script>
import { getLook,getDown }  from '@/api/user'

export default {
  name: '',
  components: {},
  props: {
    clsname:{type: String,},
  },
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      pageSize:20,
      page:1,
      total:0,
      data:[],
    }
  },
  computed: {  
  },
  watch: {},
  created () {
  },
  mounted () {},
  methods: {  
    // 异步更新数据
    async onLoad() {

      // 1. 请求获取数据
      if (this.clsname == "我的浏览") {
        try {
          const { data } = await getLook({
            page: this.page,
            pageSize: this.pageSize,
            resource_title: null,
            create_time: null,
          })
          this.data = data;
        } catch (err) {
          this.data = err;
        }
      }
      else {
        try {
          const { data } = await getDown({
            page: this.page,
            pageSize: this.pageSize,
            resource_title: null,
            create_time: null,
          })
          this.data = data;
        } catch (err) {
          this.data = err;
        }
      }

      // 2. 将数据添加到列表中
      var results = this.data.data.list;
      this.total = this.data.data.count;
      this.list.push(...results);
      // 3. 设置加载状态结束
      this.loading = false;

      // 4. 判断数据是否加载完毕
      if (results.length) {
        this.page++;// 更新获取下一页数据的页码
      } else {
        this.finished = true;// 没有数据了，将加载状态设置结束，不再 onLoad
      }
    },
  }
}
</script>

<style scoped lang="less">
.app-nav-bar{
   background: url("/img/bg_person.png") no-repeat;  
    /deep/ .van-nav-bar__title{
        color: white;
    }

    /deep/.van-icon{
        color: white;
    }
}
.date{
  margin-left: 10px;
}

</style>